package com.ryt.tuangou.service.impl;

import com.github.pagehelper.PageHelper;
import com.ryt.tuangou.mapper.ProductMapper;
import com.ryt.tuangou.pojo.PageUtil;
import com.ryt.tuangou.pojo.Product;
import com.ryt.tuangou.service.ProductService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.time.LocalDateTime;
import java.util.List;

@Service
public class ProduvtServicelmpl implements ProductService {

    @Autowired
    private ProductMapper productMapper;

    //添加商品

    @Override
    public Boolean addProduct(Product product) {
        if(product.getProductName()==null||product.getProductName().equals("")){
            return false;
        }
        product.setCreateTime(LocalDateTime.now().toString());
        product.setUpdateTime(LocalDateTime.now().toString());
        return productMapper.addProduct(product);
    }

    //分页
    @Override
    public List<Product> getList(PageUtil pageUtil) {
        //开启分页
        PageHelper.startPage(pageUtil.getPageNum(),pageUtil.getPageSize());
        //查商品数据
        List<Product> list = productMapper.getList(pageUtil);
        return list;
    }
    //删除商品removeProduct
    @Override
    public Boolean removeProduct(Product product) {
        return productMapper.removeProduct(product);
    }
    //查询回显
    @Override
    public Product getPidByProduct(Integer productId) {
        return productMapper.getPidByProduct(productId);
    }

    //修改商品
    @Override
    public Boolean updateProduct(Product product) {
        product.setUpdateTime(LocalDateTime.now().toString());
        return productMapper.updateProduct(product);
    }



}
